package com.six.firstpage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.core.entity.Article;

import com.six.firstpage.service.ArticleService;
import com.six.firstpage.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ZZH
* @description 针对表【tb_article】的数据库操作Service实现
* @createDate 2023-02-28 14:45:09
*/
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
    implements ArticleService{

    @Autowired
    private ArticleMapper articleMapper;

    //根据navid查询
    @Override
    public Article getArticlByNavId(String navId) {
        QueryWrapper<Article> wrapper = new QueryWrapper<>();
        wrapper.eq("nav_id",navId);
        return articleMapper.selectOne(wrapper);

    }

    //查询所有底部文章链接
    @Override
    public List<Article> getAllArticle() {
      return articleMapper.selectList(null);
    }

    //添加底部文章
    @Override
    public Integer addArticle(Article article) {

        UpdateWrapper<Article> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",article.getId());
        wrapper.set("art_desc",article.getArtDesc());
        return articleMapper.update(null,wrapper);
    }

    //修改底部文章
    @Override
    public Integer updateArticle(Article article) {
        return articleMapper.updateById(article);
    }

    //逻辑删除底部文章
    @Override
    public Integer delArticle(Integer id) {
        UpdateWrapper<Article> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("is_deleted",1);
        return articleMapper.update(null,wrapper);
    }
}




